###########################################################################
# $Id: dbField.p 15 2009-04-24 04:14:14Z donbeave $
###########################################################################

@CLASS
dbField

@USE
db/models/dbItem.p
labour/tests/labourAssert.p

@BASE
dbItem

#----- Constructor -----

@create[hshOptions]
## hshOptions.name
## hshOptions.type
## hshOptions.defaultValue
## hshOptions.isNull
  ^BASE:create[$hshOptions]

  ^pfAssert:isTrue(def $hshOptions.name && $hshOptions.name is string)[Name is wrong.]
  ^pfAssert:isTrue(def $hshOptions.type && $hshOptions.type is string)[Type is wrong.]

  $self._name[$hshOptions.name]
  $self._type[^hshOptions.type.upper[]]
  $self._defaultValue[$hshOptions.defaultValue]
  $self._null[^hshOptions.isNull.bool(false)]

#----- Properties -----

@GET_name[]
  $result[$_name]

@SET_name[strName]
#TODO изменение названия колонки в БД

@GET_type[]
  $result[$_type]

@GET_defaultValue[]
  $result[$_defaultValue]

@GET_isNull[]
  $result[$_null]

@GET_schema[]
  $oSchemas[^MANAGER.getSchemas[]]

  ^oSchemas.foreach[oSchema]{
    ^if($oSchema.name eq $self._schemaName){
      $result[$oSchema]
    }{
       ^pfAssert:fail[Schema not specified.]
     }
  }

@GET_table[]
  $oTables[^MANAGER.getTables[]]

  ^oTables.foreach[oTable]{
    ^if($oTable.name eq $self._tableName){
      $result[$oTable]
    }{
       ^pfAssert:fail[Table not specified.]
     }
  }

#----- Private -----

@_setSchemaName[strName]
  $self._schemaName[$strName]

@_setTableName[strName]
  $self._tableName[$strName]